<html>
<head>
  <meta charset="utf-8">
  <title>待发送商品/首页----微信发单后台</title>
  <!-- 在移动端不缩放 -->
  <!-- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    @include('public.style')
</head>


<body>
    @include('public.navbar')


 <div style="margin: 0 20px;">

<table id="demo" class="layui-table" lay-filter="test" lay-data="{height: 'full-200'}"></table>

<script type="text/html" id="barDemo">
  <a class="layui-btn" lay-event="edit">修改</a>
  <a class="layui-btn layui-btn-danger" lay-event="page-up">上移</a>
  <a class="layui-btn layui-btn-normal" lay-event="page-down">下移</a>
  <a class="layui-btn layui-btn-normal" lay-event="top">置顶</a>
  <a class="layui-btn layui-btn-normal" lay-event="del">下架</a>
</script>
 </div>

	@include('public.script')

<script type="text/javascript">
layui.use('table', function(){
    var table_url = '/user/get_list?status=0';
  var table = layui.table,form = layui.form;

  //table数据模板
  var table_index = table.render({
    elem: '#demo',
	cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	//height:'full',
	height:1000,
    url: table_url, //数据接口
    page: true ,//开启分页
	//toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
    cols: [[ //表头
		 {field: 'ID', title: 'ID', width:50, align: 'center'},
		 {
            field: 'goodsImage',
            title: '推广图',
			width:120,
			align: 'center',
            templet: function(d){
                return '<div><img id="'+d.ID+'tgimg" src="'+d.goodsImage+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
            }
        },{
            field: 'sucai1',
            title: '素材1',
			width:120,
			align: 'center',
            templet: function(d){
				if(d.sucai1 !== null && d.sucai1 !== ""){
					if(d.sucai1.indexOf("mp4") != -1){
						return '<div><video controls="controls" id="'+d.ID+'tgimg" src="'+d.sucai1+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
					}else if(d.sucai1.indexOf("jpg") != -1 || d.sucai1.indexOf("jpeg") != -1 || d.sucai1.indexOf("png") != -1){
						return '<div><img id="'+d.ID+'tgimg" src="'+d.sucai1+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
					}else{
						return '<div>无</div>';
					}
				}else{
					return '<div>无</div>';
				}

            }
        },{
            field: 'sucai2',
            title: '素材2',
			width:120,
			align: 'center',
            templet: function(d){

				if(d.sucai2 !== null && d.sucai2 !== ""){
					if(d.sucai2.indexOf("mp4") != -1){
						return '<div><video controls="controls" id="'+d.ID+'tgimg" src="'+d.sucai1+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
					}else if(d.sucai2.indexOf("jpg") != -1 || d.sucai2.indexOf("jpeg") != -1 || d.sucai2.indexOf("png") != -1){
						return '<div><img id="'+d.ID+'tgimg" src="'+d.sucai2+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
					}else{
						return '<div>无</div>';
					}
				}else{
					return '<div>无</div>';
				}

            }
        },{
            field: 'sucai3',
            title: '素材3',
			width:120,
			align: 'center',
            templet: function(d){
                if(d.sucai3 !== null && d.sucai3 !== ""){
                					if(d.sucai3.indexOf("mp4") != -1){
                						return '<div><video controls="controls" id="'+d.ID+'tgimg" src="'+d.sucai1+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
                					}else if(d.sucai3.indexOf("jpg") != -1 || d.sucai3.indexOf("jpeg") != -1 || d.sucai3.indexOf("png") != -1){
                						return '<div><img id="'+d.ID+'tgimg" src="'+d.sucai3+'" alt="" class="layui-upload-img" onclick="previewImg(this)"></div>';
                					}else{
                						return '<div>无</div>';
                					}
                				}else{
                					return '<div>无</div>';
                				}

            }
        },
		{
		    field: 'docment',
			title: '文案',
			width: 280,
			align: 'center',
		    templet: function(d){
				d.docment = Base64.decode(d.docment);
		        return '<textarea id="' + d.ID + 'checkinfo" placeholder="商品文案" class="layui-textarea">' + d.docment + '</textarea>';
		        //return '<div>' + d.docment + '</div>';
		    }
		},{
		    field: 'upcment',
			title: '补刀',
			width: 280,
			align: 'center',
		    templet: function(d){
				if(d.upcment != null && d.upcment != ""){
					d.upcment = Base64.decode(d.upcment);
				}else{
					d.upcment = "";
				}

		        return '<textarea id="' + d.ID + 'checkinfo" placeholder="补刀段子" class="layui-textarea">' + d.upcment + '</textarea>';
		    }
		},
		{fixed: 'right', title:'操作', toolbar: '#barDemo', width:400, align: 'center'}
		]]

  });


    //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
	console.log(data);
	var ID = data.ID;

    if(obj.event === 'del'){
		var statu = 0;
		//alert(uid);
	 layer.confirm('真的要下架么？', function(index){
	         obj.del();
	         layer.close(index);
			 // del_goods(ID);
             $.get("/user/goods_list_order?order=del&ID="+ID, function(result){
                 layer.msg(result.msg);
                 layui.table.reload('demo',{url:table_url , page:{curr:$(".layui-laypage-em").next().html()}});//表格重载
               },"json");
	       });

	}
else if(obj.event === 'edit'){
    var index = layer.open({
      type: 2,
      title: '修改商品',
      shadeClose: true,
      shade: false,
      content: '/user/iframe?ID='+ID,
      area: ['320px', '195px'],
      maxmin: true
    });
    layer.full(index);

    }
else if(obj.event === 'top'){
	var data = obj.data;
	var ID = data.ID;
	$.ajax({
          //几个参数需要注意一下
              type: "GET",//方法类型
              dataType: "json",//预期服务器返回的数据类型
              url: "/user/goods_list_order?order=top&ID="+ID ,//url
              success: function(res){
                  if (res.code == 0){  //修改成功

                        layer.msg("置顶成功");
                        layui.table.reload('demo',{url:table_url , page:{curr:$(".layui-laypage-em").next().html()}});//表格重载


                  }else {  //修改失败
                      //修改失败处理代码...
                      layer.msg("置顶失败");

                    }
                                   }

          });   	//post提交数据结束
	}
else if(obj.event === 'page-up'){
	var data = obj.data;
	var ID = data.ID;
	var index = data.index;
	$.ajax({
          //几个参数需要注意一下
              type: "GET",//方法类型
              dataType: "json",//预期服务器返回的数据类型
              url: "/user/goods_list_order?order=page-up&index="+index+"&ID="+ID ,//url
              success: function(res){
                  if (res.code == 0){  //修改成功

                        layer.msg("上移成功");
                        layui.table.reload('demo',{url:table_url , page:{curr:$(".layui-laypage-em").next().html()}});//表格重载


                  }else {  //修改失败
                      //修改失败处理代码...
                      layer.msg("上移失败");

                    }
                                   }

          });   	//post提交数据结束
	}
else if(obj.event === 'page-down'){
	var data = obj.data;
	var ID = data.ID;
	var index = data.index;
	$.ajax({
          //几个参数需要注意一下
              type: "GET",//方法类型
              dataType: "json",//预期服务器返回的数据类型
              url: "/user/goods_list_order?order=page-down&index="+index+"&ID="+ID ,//url
              success: function(res){
                  if (res.code == 0){  //修改成功

                        layer.msg("下移成功");
                        layui.table.reload('demo',{url:table_url , page:{curr:$(".layui-laypage-em").next().html()}});//表格重载


                  }else {  //修改失败
                      //修改失败处理代码...
                      layer.msg("下移失败");

                    }
                                   }

          });   	//post提交数据结束
	}

  });
});
</script>

<script>

    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        var height = img.height*2/3 + 50; //获取图片高度
        var width = img.width*2/3; //获取图片宽度
        var imgHtml = "<img width='" + width + "' height='" + height + "' src='" + obj.src + "' />";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: '100px',//坐标
            area: [width + 'px',height+'px'],
            shadeClose:true,//点击外围关闭弹窗
            scrollbar: false,//不现实滚动条
           // title: "图片预览", //不显示标题
            title: false, //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }
</script>
<script>
	function check(obj){
		var uid = obj.id;
		var checkbox =  document.getElementById(uid+'checkbox').children(":first").innerhtml();

		alert(checkbox);

	}

	</script>
</body>
</html>
